<?php 
namespace app\index\controller;
use \think\Controller;
use \think\Db;
use app\index\model\VerCode;
use \think\Loader;
class Reg extends Controller
{
    public function index()
    {

    	$ques = (new VerCode)->getRandOne();

        return $this->fetch('',['ques'=>$ques]);
    }

    public function add()
    {
    	$data = input('post.');
        $validate = Loader::validate('User');
        if(!$validate->check($data)){
            return ['error'=>1,'info'=>$validate->getError(),'session'=>session('answer')];
        }
        unset($data['vercode']);
        unset($data['repassword']);
        $data['password'] = md5($data['password']);
        $data['ctime'] = time();
		$res = Db::table('user')->insert($data);
        if($res){
            return ['error'=>0,'info'=>'注册成功'];
        }else{
            return ['error'=>1,'info'=>'注册失败'];
        }
    }
}

 ?>